// pages/balance/balance.js
const app = getApp()
const Host = require('../../config').Host
Page({

    /**
     * 页面的初始数据
     */
    data: {
        total_balance: 0,
        list: [],
    },
  withdraw: function () {
    var that = this;
    if (parseInt(that.data.total_balance)==0) {//小于1元没有提现资格
      wx.showToast({
        title: '余额不足提现',
        icon: 'none',
      })
    } else {
      wx.navigateTo({
        url: '/pages/withdraw/withdraw',
      })
    }
    // wx.navigateTo({
    //   url: '/pages/withdraw/withdraw',
    // })
  },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
      var openid = wx.getStorageSync('openid');
      //console.log(openid)
      var that = this;
      wx.request({
        url: Host + 'Mine/mineAssetsDetail',
        data: { openid },
        method: 'post',
        header: { 'content-type': 'application/x-www-form-urlencoded' },
        success: function (res) {
          if (res.data.code==200) {
            that.setData({         
              total_balance: res.data.drawcommission,
              list: res.data.commission,
            });
          } else {
            wx.showToast({
              title: res.data.errmsg,
              icon: 'none',
            })
            setTimeout(function () {
              wx.switchTab({
                url: '/pages/personal/personal',
              })
            }, 1000)
          }
        },
      })

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})